/* -----------------------------------------------------------------------
 * Demonstration of how to write unit tests for dominion-base
 * Include the following lines in your makefile:
 *
 * unittest1: unittest1.c dominion.o rngs.o
 *      gcc -o unittest1 -g  unittest1.c dominion.o rngs.o $(CFLAGS)
 * -----------------------------------------------------------------------
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 0

int main() {
    int numTest = 10;
    int seed = 1000;
    int numPlayer = 2;
    int p, r, i, result;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;
    int maxHandCount = 5;
	int preShuffleCount;
    // arrays of all coppers, silvers, and golds
    int coppers[MAX_HAND];
    int preShuffle[MAX_HAND];
    for (i = 0; i < MAX_HAND; i++)
    {
        coppers[i] = copper;
        preShuffle[i] = curse;
    }
	
	
    printf("TESTING shuffle():\n\n");
	printf("Number of tests: %d\nNumber of players: %d\nSeed: %d\n\n", numTest, numPlayer, seed);
	//shuffle deck when deck is full
	//shuffle deck when deck is empty
	//further testing should include validation of cards from discard to deck
	
    for (i = 0; i < numTest; i++){
		for (p = 0; p < numPlayer; p++){
		
#if (NOISY_TEST == 1)
            printf("The full deck count for player%d\n", p);
#endif
			//test 1
            memset(&G, 23, sizeof(struct gameState));   			// clear the game state
            r = initializeGame(numPlayer, k, seed, &G); 			// initialize a new game
			memcpy(preShuffle, G.deck[p], sizeof(int) * MAX_HAND);	//copy deck into preShuffle
			//memcpy(preShuffleCount, G.deckCount[p], sizeof(int));	//copy deck count
			preShuffleCount = G.deckCount[p];
			
            //G.deckCount[p] = handCount;               // set the number of cards on hand
            //memcpy(G.deck[p], coppers, sizeof(int) * handCount); // set all the cards to copper
            result = shuffle(p, &G);
#if (NOISY_TEST == 1)
            printf("deck count = %d, expected = %d\n", G.deckCount[p], preShuffleCount);
			printf("result = %d, expected = %d\n\n", result, 0);
#endif
            assert(result == 0); // check if shuffle failed
            
			
			//test 2 
			G.deckCount[p] = 0;               // set the number of cards in deck to 0
            memcpy(G.discard[p], coppers, sizeof(int) * MAX_HAND); // set discard to all the coppers
			G.discardCount[p] = maxHandCount;
            result = shuffle(p, &G);
#if (NOISY_TEST == 1)
            printf("deck count = %d, expected = %d\n", G.deckCount[p], maxHandCount);
			printf("result = %d, expected = %d\n\n", result, 0);
#endif
            assert(result == 0); // check if shuffle failed
				
        }
    }

    printf("All tests passed!\n");

    return 0;
}
